package com.souku.finance.application.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by lenovo on 2016/6/5.
 */
public class ShareUtil {

    private static ShareUtil shareUtil;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;


    public static ShareUtil getInstance() {
        if (shareUtil == null) {
            synchronized (ShareUtil.class) {
                if (shareUtil == null)
                    shareUtil = new ShareUtil();
            }
        }
        return shareUtil;
    }

    public void init(Context context) {
        sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        editor = sp.edit();
    }

    public ShareUtil putExtra(String key, String value) {
        editor.putString(key, value);
        editor.commit();
        return shareUtil;
    }

    public ShareUtil putExtra(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
        return shareUtil;
    }

    public ShareUtil putExtra(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.commit();
        return shareUtil;
    }

    public String getString(String key) {
        return sp.getString(key, null);
    }

    public boolean getBoolean(String key) {
        return sp.getBoolean(key, false);
    }

    public int getInt(String key) {
        return sp.getInt(key, -1);
    }

    public void remove(String key) {
        editor.remove(key);
        editor.commit();
    }

    public void getOut() {
        remove(Constant.IsLogin);
        remove(Constant.GesturePass);
        remove(Constant.IsBind);
        remove(Constant.IsBorrower);
        remove(Constant.IsNewHand);
        remove(Constant.IsReal);
        remove(Constant.IsSetPayPwd);
        remove(Constant.IsRole);
        remove(Constant.Token);
        remove(Constant.AvatarUrl);
    }
}
